<template>
  <div class="goods-hot">
    <h3>{{ titles[type] }}</h3>
    <GoodsItem v-for="item in result" :key="item.id" :goods="item"></GoodsItem>
  </div>
</template>
<script>
import GoodsItem from "../../categroy/components/GoodsItem";
import { ref } from "vue";
import { getHotGoods } from "../../../api/goods";
import { useRoute } from "vue-router";

export default {
  name: "GoodsHot",
  components: { GoodsItem },
  props: {
    type: {
      type: Number,
      default: 1,
    },
  },
  setup(props) {
    const route = useRoute();

    const { result, getData, titles } = useHotData();
    getData(route.params.id, props.type);

    return { result, titles };
  },
};

function useHotData() {
  const result = ref({});

  const titles = ref({
    1: "24小时榜",
    2: "周榜",
    3: "总榜",
  });

  const getData = (id, type) => {
    getHotGoods(id, 3, type).then((data) => {
      console.log(data.result);
      result.value = data.result;
    });
  };

  return {
    result,
    getData,
    titles,
  };
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  :deep(.goods-item) {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;
    img {
      width: 200px;
      height: 200px;
    }
    p {
      margin: 0 10px;
    }
    &:hover {
      transform: none;
      box-shadow: none;
    }
  }
}
</style>
